package priv.yiyuan.example.design;

import java.io.IOException;
import java.util.Base64;

/**
 * 加密装饰器
 *
 * @author YiYuan
 * @data 2025/8/8
 * @apoNote
 */
public class EncryptionDecorator extends DataReaderDecorator {

    public EncryptionDecorator(DataReader wrappedReader) {
        super(wrappedReader);
    }

    @Override
    public String read() throws IOException {
        String originalData = wrappedReader.read();
        return this.encrypt(originalData);
    }

    private String encrypt(String data) {
        return Base64.getEncoder().encodeToString(data.getBytes());
    }

    @Override
    public String getSourceInfo() {
        return "[Encrypted] " + wrappedReader.getSourceInfo();
    }
}
